#!/usr/bin/env python
# -*- coding: utf-8 -*-

from selenium.webdriver.common.by import By
from po import Page


class oalogin(Page):
    # 定位器
    username_loc = (By.NAME, "adminuser")
    password_loc = (By.NAME, "adminpass")
    rempass_loc = (By.NAME, "rempass")
    submit_loc = (By.NAME, "button")
    msgview_loc = (By.XPATH, "//*[@id='msgview']/span")
    url = '/'

    def open(self):
        self._open(self.url)

    def type_username(self, username):
        self.find_element(*self.username_loc).clear()
        self.find_element(*self.username_loc).send_keys(username)

    def type_password(self, password):
        self.find_element(*self.password_loc).clear()
        self.find_element(*self.password_loc).send_keys(password)

    def submit(self):
        self.find_element(*self.submit_loc).click()

    def click_rempass(self):
        self.find_element(*self.rempass_loc).click()

    def get_msg(self):
        return self.find_element(*self.msgview_loc).text

    def click_link(self, link):
        link_loc = (By.LINK_TEXT, u+link)
        self.find_element(link_loc)

    def login(self, username, password):
        self.type_username(username)
        self.type_password(password)
        self.submit()
